{extend name="public/base"/}
{block name="body"}
<style type="text/css">
	.attrs{margin-top:5px;}
	.attrname{width:100px;border:solid 1px #ddd;height:31px;font-size:14px;padding-left:4px;}
	.attrval{width:100%;border:solid 1px #ddd;height:31px;font-size:14px;padding-left:4px;}
	#preview img{background-color:#1c73d3;}
</style>
<title>编辑经典案例</title>
</head>
<body>
<article class="page-container">
	<form class="form form-horizontal section" id="form-admin-add">
		<section>
			<input type="hidden" class="input-text" value="{$data.id}" id="id" name="id">
			<div class="row cl">
				<label class="form-label col-xs-3 col-sm-2">案例类型：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<span class="select-box" style="width:150px;">
						<select class="select" name="type" size="1">
							<option value="1" {if $data.type==1}selected{/if}>高端定制</option>
							<option value="2" {if $data.type==2}selected{/if}>微信小程序</option>
							<option value="3" {if $data.type==3}selected{/if}>APP开发</option>
							<option value="4" {if $data.type==4}selected{/if}>社区电商</option>
							<option value="5" {if $data.type==5}selected{/if}>企业微信</option>
							<option value="6" {if $data.type==6}selected{/if}>新媒体运营</option>
						</select>
					</span>
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-3 col-sm-2">ICON：</label>
				<div class="formControls col-xs-8 col-sm-9">
	                <div style="position:relative;" id="drop_area"></div>
	                <p style="color:#ccc;font-size:12px;">建议尺寸宽高:380:250</p>
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-3 col-sm-2">APP首页图片：</label>
				<div class="formControls col-xs-8 col-sm-9">
	                <div style="position:relative;" id="drop_area_ui"></div>
	                <p style="color:#ccc;font-size:12px;">建议尺寸宽高:225:450</p>
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-3 col-sm-2">名称：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="text" class="input-text" value="{$data.title}" placeholder="名称" id="title" name="title">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-3 col-sm-2">类型描述：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="text" class="input-text" value="{$data.description}" placeholder="类型描述" id="description" name="description">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-3 col-sm-2">链接：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="text" class="input-text" value="{$data.link}" placeholder="链接" id="link" name="link">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-3 col-sm-2">二维码：</label>
				<div class="formControls col-xs-8 col-sm-9">
	                <div style="position:relative;" id="drop_area_qr"></div>
	                <p style="color:#ccc;font-size:12px;">建议尺寸宽高:100:100</p>
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-3 col-sm-2">详情：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<script id="editor" name="detail" type="text/plain" style="width:100%;height:400px;">{:htmlspecialchars_decode($data.detail)}</script>
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-3 col-sm-2">SEO关键词：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="text" class="input-text" value="{$data.seo_keywords}" id="seo_keywords" name="seo_keywords">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-3 col-sm-2">SEO描述：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="text" class="input-text" value="{$data.seo_description}" id="seo_description" name="seo_description">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-3 col-sm-2">是否启用：</label>
				<div class="formControls col-xs-8 col-sm-9">
	               <label class="radio-inline">
	                   <input type="radio" id="emailwy1" name="state" value="1" {if $data['state']==1}checked{/if} />
	                   <label for="emailwy1">是</label>
	               </label>
	               <label class="radio-inline">
	                   <input type="radio" id="emailwy2" name="state" value="2" {if $data['state']==2}checked{/if} />
	                   <label for="emailwy2">否</label>
	               </label>
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-3 col-sm-2">排序：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="number" class="input-text" value="{$data.sort}" placeholder="0" id="sort" name="sort">
				</div>
			</div>

		</section>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
				<input id="submit" class="btn btn-primary radius" type="button" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
			</div>
		</div>
	</form>
</article>
<script type="text/javascript" src="/static/lib/jquery.validation/1.14.0/jquery.validate.js"></script> 
<script type="text/javascript" src="/static/lib/jquery.validation/1.14.0/validate-methods.js"></script> 
<script type="text/javascript" src="/static/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript" src="/static/lib/ueditor/1.4.3/ueditor.config.js"></script>
<script type="text/javascript" src="/static/lib/ueditor/1.4.3/ueditor.all.min.js"> </script>
<script type="text/javascript" src="/static/lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" src="/static/js/upload.js"></script>
<script type="text/javascript">
var formDataimg = new FormData();
var formDataqrcode = new FormData();
var formDataui = new FormData();
var icon='';
var qrcode='';
var phone_img='';
$(function(){
	$('#drop_area div img').attr('src','{$data.icon}');
	$('#drop_area div img').attr('onerror',"javascript:this.src='/static/img/upload.png'");
	if($("#drop_area div img").attr('src')=='/static/img/upload.png'){
		icon='';
	}else{
		icon= `{$data.icon}`;
	}
	$('#drop_area_qr div img').attr('src','{$data.qrcode}');
	$('#drop_area_qr div img').attr('onerror',"javascript:this.src='/static/img/upload.png'");
	if($("#drop_area_qr div img").attr('src')=='/static/img/upload.png'){
		qrcode='';
	}else{
		qrcode= `{$data.qrcode}`;
	}
	$('#drop_area_ui div img').attr('src','{$data.phone_img}');
	$('#drop_area_ui div img').attr('onerror',"javascript:this.src='/static/img/upload.png'");
	if($("#drop_area_ui div img").attr('src')=='/static/img/upload.png'){
		phone_img='';
	}else{
		phone_img= `{$data.phone_img}`;
	}
	var ue = UE.getEditor('editor');
	  $("#emailwy1").on('click',function(){
		$("#emailwy2").attr('checked', false);
		$(this).attr('checked', true);
	  });
	  $("#emailwy2").on('click',function(){
		$("#emailwy1").attr('checked', false);
		$(this).attr('checked', true);
	  });
});

var dragImgUpload = new DragImgUpload("#drop_area",{
    callback:function (files) {
        //回调函数，可以传递给后台等等
        if(files[0].size<3145728){
	        var file = files[0];
	        formDataimg.append("file",file);
        }else{
        	alert('出错');
        	location.replace(location.href);
        }
    }
});
var dragImgUpload = new DragImgUpload("#drop_area_qr",{
    callback:function (files) {
        //回调函数，可以传递给后台等等
        if(files[0].size<3145728){
	        var tfile = files[0];
	        formDataqrcode.append("file",tfile);
        }else{
        	alert('出错');
        	location.replace(location.href);
        }
    }
});
var dragImgUpload = new DragImgUpload("#drop_area_ui",{
    callback:function (files) {
        //回调函数，可以传递给后台等等
        if(files[0].size<3145728){
	        var tfile = files[0];
	        formDataui.append("file",tfile);
        }else{
        	alert('出错');
        	location.replace(location.href);
        }
    }
});
$("#submit").click(function() {
	layer.load(1, {
	  shade: [0.1,'#fff'] //0.1透明度的白色背景
	});
	var id=$("input[name=id]").val();
	var title=$("input[name=title]").val();
	var description=$("input[name=description]").val();
	var link=$("input[name=link]").val();
	var seo_keywords=$("input[name=seo_keywords]").val();
	var seo_description=$("input[name=seo_description]").val();
	var sort=$("input[name=sort]").val();
	var detail=UE.getEditor('editor').getContent();
	var state=$("input[name=state][checked]").val();
	var type=$("select[name=type]").val();
	if(formDataimg.get("file")||formDataqrcode.get("file")||formDataui.get("file")){
	    if(formDataimg.get("file")){
		    $.ajax({
		          type: 'POST',
		          url: "{:url('uploadtmd')}",
		          data:formDataimg,
		          async:false,
		          contentType: false, /*不可缺*/
		          processData: false, /*不可缺*/
		          success: function(response){
		            if(response.code==200){
		            	icon=response.photo;
		            }
		          },
		          error: function(err){
		          	console.log('formDataimg'+err)
		          }
		    })
		}
		if(formDataqrcode.get("file")){
		    $.ajax({
		          type: 'POST',
		          url: "{:url('uploadtmd')}",
		          data:formDataqrcode,
		          async:false,
		          contentType: false, /*不可缺*/
		          processData: false, /*不可缺*/
		          success: function(response){
		            if(response.code==200){
		            	qrcode=response.photo;
		            }
		          },
		          error: function(err){
		          	console.log('formDataqrcode'+err)
		          }
		    })
		}
		if(formDataui.get("file")){
		    $.ajax({
		          type: 'POST',
		          url: "{:url('uploadtmd')}",
		          data:formDataui,
		          async:false,
		          contentType: false, /*不可缺*/
		          processData: false, /*不可缺*/
		          success: function(response){
		            if(response.code==200){
		            	phone_img=response.photo;
		            }
		          },
		          error: function(err){
		          	console.log('formDataui'+err)
		          }
		    })
		}
	    $.ajax({
		    type: 'POST',
	        async:false,
		    url: "{:url('cases_edit')}",
		    data: {id:id,title:title,description:description,icon:icon,qrcode:qrcode,phone_img:phone_img,sort:sort,link:link,state:state,type:type,detail:detail,seo_keywords:seo_keywords,seo_description:seo_description},
		    success: function(resdata){
		        if(resdata.code==200){
					layer.msg(resdata.msg,{icon:1,time:1000});
					setTimeout("parent.location.reload()",1000);
		        }else{
					layer.msg(resdata.msg,{icon:2,time:3000});
		        }
		    },
		    error: function(){
				layer.msg('数据保存失败',{icon:2,time:3000});
		    }
		})
	}else{
		$.ajax({
		    type: 'POST',
		    url: "{:url('cases_edit')}",
		    data: {id:id,title:title,description:description,icon:icon,qrcode:qrcode,phone_img:phone_img,sort:sort,link:link,state:state,type:type,detail:detail,seo_keywords:seo_keywords,seo_description:seo_description},
		    success: function(resdata){
		        if(resdata.code==200){
					layer.msg(resdata.msg,{icon:1,time:1000});
					setTimeout("parent.location.reload()",1000);
		        }else{
					layer.msg(resdata.msg,{icon:2,time:3000});
		        }
		    },
		    error: function(){
				layer.msg('数据保存失败',{icon:2,time:3000});
		    }
		})
	}
	
})
</script> 
{/block}